/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import Data.BoPhan;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

/**
 *
 * @author bienphongvnn
 */
public class BoPhanModel {
    public static ArrayList<BoPhan> ListBoPhan() {
        ArrayList<BoPhan> ds = new ArrayList<BoPhan>();
        Connection con = ConnectionProvider.Connect();
        try {
            String sql = "SELECT * FROM bophan";
            Statement statement = con.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                BoPhan kh = new BoPhan();
                kh.MaBP = rs.getString("MaBP");
                kh.TenBP = rs.getString("TenBP");
                kh.TruongBP = rs.getString("TruongBP");
                ds.add(kh);
            }
            con.close();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        } finally {

        }
        return ds;
    }

    //Tim kiếm
    public static ArrayList<BoPhan> TimKiemTatCa(String keyword) {
        ArrayList<BoPhan> ds = new ArrayList<BoPhan>();
        Connection conn = ConnectionProvider.Connect();
        try {
            String sql = "Select  * from bophan where MaBP = '" + keyword + "'";
            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                BoPhan kh = new BoPhan();
                kh.MaBP = rs.getString("MaBP");
                kh.TenBP = rs.getString("TenBP");
                kh.TruongBP = rs.getString("TruongBP");
                ds.add(kh);
            }

        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        } finally {

        }
        return ds;
    }
}
